const fs = require('fs');
const path = require('path');

const mapDir = './map';
const dataDir = './data';

// 读取map目录下所有的_processed.json文件
const files = fs.readdirSync(mapDir).filter(file => file.endsWith('_processed.json'));

files.forEach(file => {
  // 读取JSON文件内容
  const jsonData = JSON.parse(fs.readFileSync(path.join(mapDir, file), 'utf8'));
  
  // 转换为JS模块格式
  const jsContent = `module.exports = ${JSON.stringify(jsonData, null, 2)};`;
  
  // 写入新的JS文件
  const jsFileName = file.replace('.json', '.js');
  fs.writeFileSync(path.join(dataDir, jsFileName), jsContent);
  
  console.log(`Converted ${file} to ${jsFileName}`);
});